<template>
  <div class="score">
    <!--nav-->
    <div class="Nav">
      <Nav></Nav>
    </div>
    <!--/nav-->
    <!--content-->
    <div class="score_content">
      <div class="main_content">
        <!--作品标题-->
        <div class="title">
          <span style="float: left">{{tableData.name}}</span>
          <span>
            <el-rate v-model="tableData.num" disabled show-score :colors="colors" text-color="#ff9900" score-template="{value}"></el-rate>
          </span>
        </div>
        <el-divider></el-divider>
        <!--电影描述-->
        <div class="movie_dec" >
          <div class="movie_img">
            <img :src="'static/img/'+tableData.img" alt="">
          </div>
          <div class="people"><br>
            <span >导 &nbsp; 演：{{tableData.director}}</span><br><br>
            <span>编 &nbsp; 剧：{{tableData.producer}}</span><br><br>
            <span>主 &nbsp; 演：{{tableData.actors}}</span><br><br>
            <span>类 &nbsp; 型：{{tableData.filmClass}}</span><br><br>
            <span>制片国家：{{tableData.country}}</span><br><br>
            <span>语 &nbsp; 言：{{tableData.language}}</span><br><br>
            <span>上映年份：{{tableData.year}}</span><br><br>
            <span>片 &nbsp; 长：{{tableData.length}}</span><br><br>
          </div>
          <div class="des">
            <span>{{tableData.introduce}}</span>
          </div>
        </div>
        <!--/电影描述-->
        <div style="margin-top: 450px">
          <el-divider></el-divider>
        </div>
        <!--评分-->
        <div class="rate">
          <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item  label="请进行评分：" prop="score">
              <el-rate style="margin-top: 10px" v-model="UserScore.score" show-text :colors="colors" ></el-rate>
            </el-form-item>
            <el-form-item label="请输入评价：" prop="introduce">
              <el-input style="width: 600px" :rows="6" type="textarea" placeholder="请输入内容" v-model="UserScore.remark" maxlength="300" show-word-limit>
              </el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="addScore()">提交</el-button>
              <el-button @click="toClear()">重置</el-button>
            </el-form-item>
          </el-form>

        </div>
        <!--/评分-->
        <div>
          <el-divider></el-divider>
        </div>
        <!--热门评论-->
        <div style="height: 400px">
          <span style="font-size: 25px;font-weight: bold">用户评价</span>
          <div v-for="(item,index) in ScoreData.slice((currentPage-1)*pageSize,currentPage*pageSize)">
            <div  class="sco" style="margin-top: 10px;margin-left: 10px">
              <!--用户名称-->
              <div>
                <span style="font-size: 15px;font-weight: bold;float: left;">{{item.name}}&nbsp;&nbsp;</span>
                <span><el-rate v-model="item.score" disabled show-score :colors="colors" text-color="#ff9900" score-template="{value}"></el-rate></span>
              </div>
              <!--主体内容-->
              <div style="width: 880px;margin-top: 10px">
                <span style="width: 500px;height: 200px;color: gray">{{item.remark}}</span>
              </div>
              <!--时间-->
              <div style="margin-top: 5px">
                <span style="color:gray;font-size: 1px" :formatter="dateFormat">{{item.createTime}}</span>
              </div>
            </div>
          </div>
        </div>
        <!--/热门评论-->
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pageSize"
          layout="total, prev, pager, next"
          :total="ScoreData.length">
        </el-pagination>
        <div>
          <el-divider></el-divider>
        </div>
      </div>
    </div>
    <!--/content-->
    <!--Footer-->
    <div class="footer">
      <Footer></Footer>
    </div>
    <!--/Footer-->
  </div>
</template>

<script>
  import Nav from "../components/Nav";
  import Footer from "../components/Footer";
    export default {
      name: "Score",
      data(){
        return{
          currentPage: 1, //初始页
          pageSize: 3,    //每页的数据
          ruleForm:{},
          rules:[],
          UserScore:{},
          ScoreData:[{}],
          tableData:{},
          colors: ['#99A9BF', '#F7BA2A', '#FF9900']
        }
      },
      methods:{
        //时间格式化
        dateFormat(row, column){
          let date = row.createTime;
          return this.$moment(date).format('YYYY-MM-DD HH:mm:ss')
        },
        // 初始页currentPage、初始每页数据数pagesize和数据data
        handleSizeChange: function (size) {
          this.pagesize = size;
          console.log(this.pagesize)  //每页下拉显示数据
        },
        handleCurrentChange: function (currentPage) {
          this.currentPage = currentPage;
          console.log(this.currentPage)  //点击第几页
        },
        /*根据id查询评论信息*/
        findScore(id){
          let _this = this
          this.$axios.get("http://localhost:8088/score/getScoreById/"+id).then(function (res) {
            _this.ScoreData = res.data
            console.log(res.data)
          }).catch(function (err) {
            alert('热门电影查询失败')
          })
        },
        /*根据id查询电影信息*/
        findFilm(id){
          let _this = this
          this.$axios.get("http://localhost:8088/film/selectFilmById/"+id).then(function (res) {
            _this.tableData = res.data
            console.log(res.data)
          }).catch(function (err) {
            alert('热门电影查询失败')
          })
        },
        /*清空表单*/
        toClear(){
          this.UserScore.score = ''
          this.UserScore.remark = ''
        },
        /*用户评分添加*/
        addScore(){
          let name = localStorage.getItem("name");
          let id = localStorage.getItem("id");
          if(name==null){alert("请登录！");return false}
          if(!this.UserScore.score){alert("请输入评分！");return false}
          if(!this.UserScore.remark){alert("请输入评价！");return false}
          this.UserScore.userId = id
          this.UserScore.filmId = this.$route.query.id
          let _this = this
          console.log(this.UserScore)
          this.$axios.post("http://localhost:8088/score/setUserScore", this.UserScore).then(function () {
            //清空本次保存数据
            _this.$message({
              showClose: true,
              message: '评价成功!',
              type: 'success'
            });
            _this.UserScore = {};
            setTimeout('location.reload()', 1000);
          }).catch(function (err) {
            _this.$message({
              showClose: true,
              message: '评价失败!',
              type: 'error'
            });
          })
        }
      },
      components:{
        Nav,
        Footer
      },
      mounted() {
        this.findFilm(this.$route.query.id)
        this.findScore(this.$route.query.id)
        window.scrollTo(0,0)
      }
    }
</script>

<style scoped>
  .movie_img img{
    height: 380px;
    width: 270px;
    margin-top: 10px
  }


  .des{
    padding: 5px;
    float: left;
    width: 320px;
    height: 390px;
    font-size: 18px;
    font-weight: bold;
    background-color: white;
    border: 1px solid rgba(228, 228, 228, 0.94)
  }

  .people span{
    margin-left: 20px;
  }

  .people{
    float: left;
    width: 330px;
    height: 400px;
    background-color: white;
    border: 1px solid rgba(228, 228, 228, 0.94)
  }

  .movie_img{
    float: left;
    width: 270px;
    height: 400px;
    background-color: white;
    border: 1px solid rgba(228, 228, 228, 0.94)
  }

  .movie_dec{
    margin-left: 10px
  }
  .title{
    font-size: 25px;
    font-weight: bold;
  }

  .main_content{
    width: 960px;
    height: 1000px;
  }

  .score_content{
    padding: 20px;
    border-radius: 5px;
    width: 960px;
    height: 1300px;
    background-color: white;
    margin-top: 20px;
    margin-left: 270px;
    margin-bottom: 10px;
  }
  .score{
    width: 100%;
    height: 1440px;
    background-color: rgba(238,236,237,0.94);
  }
</style>
